package com.xiangyang.utils;

import com.xiangyang.entity.vo.VerifyVo;
import com.xiangyang.exception.VerifyInfoException;

public class VerifyInfo {
     public static void VerifyInfo (VerifyVo verifyVo) throws VerifyInfoException {
        //手机号的校验
        if (verifyVo.getPhone()!=null){
             String verifyPhone =   "^(13[0-9]|17[0-9]|19[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
             if (!verifyVo.getPhone().matches(verifyPhone)){
                throw new VerifyInfoException("手机号格式不正确");
             }
        }
          //密码的校验
        if (verifyVo.getPassword()!=null){
             String verifyPassword = "^(?=.*[0-9])(?=.*[a-zA-Z])(.{8,12})$";
             if (!verifyVo.getPassword().matches(verifyPassword)){
                throw new VerifyInfoException("密码格式不正确");
             }
        }
        if (verifyVo.getEmail()!=null){
             String verifyEmail = "^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+";
             if (!verifyVo.getEmail().matches(verifyEmail)){
                throw new VerifyInfoException("邮箱格式不正确");
             }
        }
        if (verifyVo.getIdCard()!=null){
             String verifyIdCard = "^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
             if (!verifyVo.getIdCard().matches(verifyIdCard)){
                throw new VerifyInfoException("身份证号格式不正确");
             }
        }
        if (verifyVo.getCode()!=null){
            String verifyCode = "^[0-9]{6}$";
            if (!verifyVo.getCode().matches(verifyCode)){
                throw new VerifyInfoException("验证码格式不正确");
            }
        }
    }
}
